<?php
/*
 * @package WordPress
 * @subpackage ZeroWeight
 * 
 * Created by John Przeslakowski
 * http://blog.przeslakowski.com
 *
 */
?>
<?php

$fields = array(
	'author' => '<p class="comment-form-author">' . '<label for="author">' . 'Your name'. ($req ? '<span class="required">*</span>' : '') . '</label> ' .
	'<input id="author" name="author" type="text" placeholder="Can either be your nick or full name" value="' . esc_attr($commenter['comment_author']) . '" size="30" required="required" /></p>',
	'email' => '<p class="comment-form-email"><label for="email">' . 'Your e-mail' . ($req ? '<span class="required">*</span>' : '') . '</label> ' .
	'<input id="email" name="email" type="email" placeholder="Make sure, it\'s real" value="' . esc_attr($commenter['comment_author_email']) . '" size="30" required="required" /></p>');

$logged_in = '<p class="zero-msg info logged-in-as">' . sprintf(__('You are posting as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Not you?</a>'), admin_url('profile.php'), $user_identity, wp_logout_url(apply_filters('the_permalink', get_permalink()))) . '</p>';

apply_filters('comment_form_default_fields', $fields);

$args = array(
	'fields' => $fields,
	'comment_field' => '<p class="comment-form-comment"><label for="comment">Comment text</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="true" placeholder="Your thoughts go here"></textarea></p>',
	'comment_notes_after' => '<p class="zero-comments-tip">You can use <code>&lt;q cite="SOMEBODYS_NAME"&gt;</code> to quote others and <code>&lt;code&gt;</code> to hightlight source code.</p>',
	'logged_in_as' => $logged_in
);

if(post_password_required()){
	echo '<p class="zero-msg warning">This post is password protected. Enter the password to view comments.</p>';
	return;
}

function zero_comments($comment, $args, $depth) {
	
	$GLOBALS['comment'] = $comment; ?>
	
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
		<div id="comment-<?php comment_ID(); ?>" class="zero-comment<?php if (1 == $comment->user_id) echo ' author'; ?>">
			<?php if(empty($comment->comment_parent)): ?>				
				<div class="zero-author-avatar">					
					<?php if($comment->comment_type == "pingback" || $comment->comment_type == "trackback"): ?>
						<img alt="<?php comment_author(); ?>" src="<?php echo get_stylesheet_directory_uri(); ?>/img/ping.png" class="avatar avatar-48 photo" height="48" width="48">
					<?php else: ?>
						<?php echo get_avatar($comment, $size='48'); ?>
					<?php endif; ?>
				</div>
				
				<div class="zero-comment-bubble">
					<h4 class="zero-author-name"><cite><?php comment_author_link(); ?></cite> <span>wrote:</span></h4>
					
					<?php if ($comment->comment_approved == '0') : ?>
						<em>Your comment is awaiting moderation.</em>
					<?php endif; ?>
					
					<div class="zero-comment-body"><?php comment_text() ?></div>
					
					<div class="zero-meta">
						<time class="zero-comment-date" datetime="<?php comment_date('Y-m-d'); ?>T<?php comment_time('H:i:s'); ?>">
							<?php echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; ?>
							<?php edit_comment_link('Edit'); ?>
						</time>
						<div class="zero-comment-reply">
							<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
						</div>
					</div>					
				</div>
			<?php else: ?>
				<div class="zero-comment-answer">
					<div class="zero-author-avatar"><?php echo get_avatar($comment, $size='24'); ?></div>
					<h4 class="zero-author-name"><cite><?php comment_author_link(); ?></cite> <span>answered:</span></h4>
					
					<?php if ($comment->comment_approved == '0') : ?>
						<em>Your comment is awaiting moderation.</em>
					<?php endif; ?>
					
					<div class="zero-comment-body"><?php comment_text() ?></div>
					
					<div class="zero-meta">
						<time class="zero-comment-date" datetime="<?php comment_date('Y-m-d'); ?>T<?php comment_time('H:i:s'); ?>">
							<?php echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; ?>
							<?php edit_comment_link('Edit'); ?>
						</time>
						<div class="zero-comment-reply">
							<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
						</div>
					</div>
				</div>					
			<?php endif; ?>
		</div>
	<?php
}
?>

<?php if(have_comments()): ?>
	<h3><?php comments_number('No comments so far. You can be first.', 'One comment', '% comments'); ?></h3>
	
	<ul class="commentlist">
		<?php wp_list_comments('&callback=zero_comments'); ?>
	</ul>
	
	<div class="navigation">
		<div class="alignleft"><?php previous_comments_link() ?></div>
		<div class="alignright"><?php next_comments_link() ?></div>
	</div>
	
	<?php
	
	if(comments_open()):
		
		comment_form($args);
		
	else:
		?>
		<p class="zero-msg warning">Comments are closed.</p>
		<?php
	endif;
else :
	if(comments_open()):
		?>
		<p class="zero-msg info">There are no comments yet. You can be the first one!</p>
		<?php
		
		comment_form($args);
		
	else:
		?>
		<p class="zero-msg warning">Comments are closed.</p>
		<?php
	endif;
endif;


?>